<div class="doc-item" id="doc-735"><h2 class="doc-item-name">deferror<span class="namespace">(clojure.contrib.error-kit)</span></h2><p class="macro">Macro</p><ul class="var-arglists"><li>(<span class="var-name">deferror</span> name [parent-error?] doc-string? [args*] &amp; body)</li><li>(<span class="var-name">deferror</span> name [parent-error?] doc-string? args-destruct-map &amp; body)</li></ul><div class="var-docstring"><p>Define a new error type</p></div><div class="var-source"><pre>; clojure/contrib/error_kit.clj:59
(defmacro deferror
  {:arglists '([name [parent-error?] doc-string? [args*] &amp; body]
               [name [parent-error?] doc-string? args-destruct-map &amp; body])}
  [err-name pvec &amp; decl]
  (let [pvec (if (empty? pvec) [`error] pvec)
        [docstr args &amp; body] (if (string? (first decl)) decl (cons nil decl))
        args (or args [])
        argmap (if (vector? args) `{:keys ~args} args)
        body (or body {})
        qual-err-name (symbol (str *ns*) (name err-name))]
    (assert (== (count pvec) 1)) ; only support single-inheritance for now
    (assert (vector? args)) ; only vector (keyword destruct) args for now
    `(do
       (defn ~err-name [details#]
         (let [basedata# ((resolve (first (parents '~qual-err-name))) details#)
               ~argmap basedata#]
           (merge basedata# {:tag '~qual-err-name} (do ~@body) details#)))
       (alter-meta! (var ~err-name) assoc
                    :doc ~docstr ::args ~(vec (map #(keyword (str %)) args)))
       ~@(for [parent pvec]
           `(derive '~qual-err-name '~(qualify-sym parent)))
       (var ~err-name))))</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="http://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License 1.0</a>, which can be found in the file
          epl-v10.html at the root of this distribution. By using this software
          in any fashion, you are agreeing to be bound by the terms of this
          license. You must not remove this notice, or any other, from this
          software.</p></div></div>